<template>
  <div>
    <div style="margin-bottom: 15px;">
      Your roles: {{ roles }}
    </div>
    Switch roles;
    <el-radio-group v-model="switchRoles">
      <el-radio-button label="editor" />
      <el-radio-button label="admin" />
    </el-radio-group>
  </div>
</template>

<script>
export default {
  name: 'SwitchRoles'
}
</script>
<script setup>
import { computed, defineEmits } from 'vue'
import { useStore } from 'vuex'

const store = useStore()

const roles = computed(() => store.getters.roles)

const emits = defineEmits(['change'])
const switchRoles = computed({
  get: () => roles.value[0],
  set: val => {
    store.dispatch('user/changeRoles', val).then(() => {
      emits('change')
    })
  }
})
</script>
